package top.lixunda.ecommerce.server.good.api.entity.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import top.lixunda.common.validate.annotation.XumIncludes;
import top.lixunda.common.validate.annotation.XumNotNull;
import top.lixunda.ecommerce.server.business.api.entity.BusinessConstants;
import top.lixunda.ecommerce.server.good.api.entity.db.PageInfoShowDO;

/**
 * 保存首页的Featured数据DTO
 *
 * @author lixunda
 * @version time:2020/3/20 17:27
 */
@ApiModel("保存首页的Featured数据DTO")
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class PageIndexFeaturedInsertDTO {

    /**
     * 图片在左侧
     */
    @ApiModelProperty(hidden = true)
    @JsonIgnore
    public static final String DIRECTION_LEFT = "LEFT";
    /**
     * 图片在右侧
     */
    @ApiModelProperty(hidden = true)
    @JsonIgnore
    public static final String DIRECTION_RIGHT = "RIGHT";

    @ApiModelProperty("大标题")
    @XumNotNull(message = "标题不能为空")
    private String title;

    @ApiModelProperty("小标题")
    private String subTitle;

    @ApiModelProperty("图片")
    @XumNotNull(message = "图片不能为空")
    private String image;

    @ApiModelProperty("图片文件编号")
    @XumNotNull(message = "图片文件编号不能为空")
    private Integer imageFileId;

    @ApiModelProperty("商品编号")
    @XumNotNull(message = "链接商品不能为空")
    private Integer linkGoodId;

    @ApiModelProperty("展示方式，LEFT RIGHT")
    @XumNotNull(message = "展示方式不能为空")
    @XumIncludes({DIRECTION_LEFT, DIRECTION_RIGHT})
    private String direction;

    @ApiModelProperty("位置")
    @XumNotNull(message = "位置不能为空")
    private String position;

    /**
     * 转换数据，将本DTO转换为PageInfoShowDO
     *
     * @return PageInfoShowDO
     * @see top.lixunda.ecommerce.server.good.api.entity.vo.PageFeaturedVO
     */
    public PageInfoShowDO toPageInfoShowDO() {
        return new PageInfoShowDO()
                .setPage(BusinessConstants.PAGE_NAME_INDEX)
                .setModule(BusinessConstants.PAGE_MODULE_NAME_FEATURED)
                .setPosition(this.getPosition())
                .setType("")
                .setSequence(0)
                .setImage1(this.getImage())
                .setImageFile1(this.getImageFileId())
                .setLink(String.valueOf(this.getLinkGoodId()))
                .setContent1(this.getTitle())
                .setContent2(this.getSubTitle())
                .setContent3(this.getDirection());
    }

}
